#！/bin/bash
source /etc/profile
if [ -n "$1" ]
then
rollback_date=$1
else
rollback_date=`date -d "-1 day" +%F`
fi
sql="
insert overwrite table dim.dim_trade_shops(
    select 
        shopid, userid, areaid, shopname, shoplevel, status, createtime, modifytime,start_dt, end_dt
    from dim.dim_trade_shops where end_dt<'$rollback_date'                      -- end_dt 小于 rollback date 记录的在rollback日期前已经失效，无需修改
    union all
    select shopid, userid, areaid, shopname, shoplevel, status, createtime, modifytime,start_dt, '9999-12-31' as end_dt
    from dim.dim_trade_shops where start_dt<='$rollback_date' and '$rollback_date'<=end_dt;)
" 
hive -e "$sql"